package cn.school.thoughtworks.section1;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class PracticeA {
    List<String> collectSameElements(List<String> collection1, List<String> collection2) {
        //实现练习要求，并改写该行代码。
        Stream<String> stream = collection1.stream();
        Stream<String> stringStream = stream.filter(collection2::contains);
        return  stringStream.collect(Collectors.toList());

        
       /* List list=new ArrayList();
        for(int i=0;i<((collection1.size()>collection2.size())?collection1.size():collection2.size());i++){
            for(int j=0;j<((collection1.size()<collection2.size())?collection1.size():collection2.size());j++) {
                if (collection1.get(i) == collection2.get(j)) {
                    list.add(collection1.get(i));
                    System.out.println(collection1.get(i));
                }
            }
        }
        return list;*/

    }
}
